<?php declare(strict_types=1);

namespace think\msg\job;

use think\msg\facade\Msg;
use think\queue\Job;

/**
 * 执行命令：php think queue:work --queue=think-msg:msg_push
 * 异常消息推送任务
 */
class MsgPushJob
{
    /**
     * 异常消息推送任务队列名称
     */
    const QUEUE_NAME = 'think-msg:msg_push';

    /**
     * @param Job $job
     * @param array $data
     * @return void
     */
    public function fire(Job $job, array $data)
    {
        try {
            request()->requestId = $data['requestId'];
            $msg = unserialize($data['msg']);
            Msg::send($msg);
            echo Msg::getLog('异常消息推送'), PHP_EOL;
            $job->delete();
        } catch (\Throwable $e) {
            // 忽略异常
        }
    }
}